package com.zuilapsa.jmc.actions;

import java.io.*;

import com.zuilapsa.jmc.*;
import com.zuilapsa.jmc.userInterfaces.UserInterfaceSession;

/**
 * @deprecated use bsh scripts
 * @author kisune
 *
 */
public class ActionExecute extends ActionNull {

	public void execute(UserInterfaceSession interfaceSession, String[] args)
			throws JmcException {
		try {
			String[] cmd = { getAttibute("command"), getAttibute("args") };
			//TO DO add validation of arguments according to param element
			Process p = Runtime.getRuntime().exec(cmd);
			p.waitFor();
		} catch (IOException e) {
			throw new JmcException(
					"Error executing: " + getAttibute("command"), e);
		} catch (InterruptedException e) {
			throw new JmcException("Error waiting for: "
					+ getAttibute("command"), e);
		}
	}

	public String getHelpString() {
		String xmlDescription = getDefinition().attributeValue("description");
		if (xmlDescription != null)
			return xmlDescription;
		else
			return "Executes " + getAttibute("command");
	}
}
